#include <cstdio>
#define lowbit(x) (x & (-x))
const int N = 5005;
int n, map[N][N];

inline void add(int x, int y, int val) {
  for (int i = x; i <= n; i += lowbit(i)) {
    for (int j = y; j <= n; j += lowbit(j)) {
      map[i][j] += val;
    }
  }
}

inline int query(int x, int y) {
  int res = 0;
  for (int i = x; i; i -= lowbit(i)) {
    for (int j = y; j; j -= lowbit(j)) {
      res += map[i][j];
    }
  }
  return res;
}

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("testdata.in", "r", stdin);
  freopen("testdata.out", "w", stdout);
#endif
#ifndef LOCAL
  freopen("raid.in", "r", stdin);
  freopen("raid.out", "w", stdout);
#endif
#endif

  scanf("%d", &n);
  int x, y;
  for (int i = 1; i <= n; ++i) {
    scanf("%d%d", &x, &y);
    add(x, y, 1);
  }
  int ans = 0;
  for (int k = 1; k <= n; ++k)
    for (int i = k; i <= n; ++i) {
      for (int j = k; j <= n; ++j) {
        if (query(i, j) + query(i - k, j - k) - query(i, j - k) - query(i - k, j) == k) ++ans;
      }
    }
  printf("%d", ans);
  return 0;
}